package es.buffygilmore.collectionapp.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import es.buffygilmore.collectionapp.R;

public class ConfirmacionEliminarDialogFragment extends DialogFragment {
	// @Override
	// public Dialog onCreateDialog(final Bundle savedInstanceState) {
	// // Use the Builder class for convenient dialog construction
	// final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
	// builder.setMessage(R.string.dialog_eliminar_elemento)
	// .setPositiveButton(R.string.eliminar, new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(final DialogInterface dialog, final int id) {
	// // FIRE ZE MISSILES!
	// }
	// }).setNegativeButton(R.string.cancelar, new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(final DialogInterface dialog, final int id) {
	// // User cancelled the dialog
	// }
	// });
	// // Create the AlertDialog object and return it
	// return builder.create();
	// }

	/*
	 * The activity that creates an instance of this dialog fragment must implement this interface
	 * in order to receive event callbacks. Each method passes the DialogFragment in case the host
	 * needs to query it.
	 */
	public interface NoticeDialogListener {
		public void onDialogPositiveClick(DialogFragment dialog);

		public void onDialogNegativeClick(DialogFragment dialog);
	}

	// Use this instance of the interface to deliver action events
	NoticeDialogListener mListener;

	// Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
	@Override
	public void onAttach(final Activity activity) {
		super.onAttach(activity);
		// Verify that the host activity implements the callback interface
		try {
			// Instantiate the NoticeDialogListener so we can send events to the host
			this.mListener = (NoticeDialogListener) activity;
		} catch (final ClassCastException e) {
			// The activity doesn't implement the interface, throw exception
			throw new ClassCastException(activity.toString()
					+ " must implement NoticeDialogListener");
		}
	}

	@Override
	public Dialog onCreateDialog(final Bundle savedInstanceState) {
		// Build the dialog and set up the button click handlers
		final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
		builder.setMessage(R.string.dialog_eliminar_elemento)
				.setPositiveButton(R.string.eliminar, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(final DialogInterface dialog, final int id) {
						// Send the positive button event back to the host activity
						ConfirmacionEliminarDialogFragment.this.mListener
								.onDialogPositiveClick(ConfirmacionEliminarDialogFragment.this);
					}
				}).setNegativeButton(R.string.cancelar, new DialogInterface.OnClickListener() {
					@Override
					public void onClick(final DialogInterface dialog, final int id) {
						// Send the negative button event back to the host activity
						ConfirmacionEliminarDialogFragment.this.mListener
								.onDialogNegativeClick(ConfirmacionEliminarDialogFragment.this);
					}
				});
		return builder.create();
	}

	// public static class MyAlertDialogFragment extends DialogFragment {
	//
	// public static MyAlertDialogFragment newInstance(final int title) {
	// final MyAlertDialogFragment frag = new MyAlertDialogFragment();
	// final Bundle args = new Bundle();
	// args.putInt("title", title);
	// frag.setArguments(args);
	// return frag;
	// }
	//
	// @Override
	// public Dialog onCreateDialog(final Bundle savedInstanceState) {
	// final int title = this.getArguments().getInt("title");
	//
	// return new AlertDialog.Builder(this.getActivity())
	// .setIcon(android.R.drawable.ic_dialog_alert).setTitle(title)
	// .setPositiveButton(R.string.eliminar, new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(final DialogInterface dialog, final int whichButton) {
	// ((FragmentAlertDialog) ConfirmacionEliminarDialogFragment.this
	// .getActivity()).doPositiveClick();
	// }
	// }).setNegativeButton(R.string.cancelar, new DialogInterface.OnClickListener() {
	// @Override
	// public void onClick(final DialogInterface dialog, final int whichButton) {
	// ((FragmentAlertDialog) ConfirmacionEliminarDialogFragment.this
	// .getActivity()).doNegativeClick();
	// }
	// }).create();
	// }
	// }

}